﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi
{
    public partial class mfDjackRecommend : msBsc.Cls.mbPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                string djackId = this.GetParamHtValue("djackId");
                getUserInfo(djackId);
                base.DoAction();
            }
            else if (this.strAction == "telClick")
            {
                base.DoAction();
            }
            else if (this.strAction=="gopage")
            {
                getForumList();
            }
        }

        private void getUserInfo(string djackId)
        {
            if (string.IsNullOrEmpty(djackId))
            {
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizVehicleInfo vehicleInfo = new AppLogic.DataAlc.CBizVehicleInfo())
            {
                DataSet ds = vehicleInfo.SelectByIds(djackId, "");
                if (ds == null)
                {
                    return;
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                this.ExecJScript(@"SetUserBaseInfo(" + retJson + ");");
                getForumList();
            }
        }

        private void getForumList()
        {
            string pIndex = this.GetParamHtValue("pIndex");
            string pRows = this.GetParamHtValue("pRows");
            using (msBsc.AppLogic.DataAlc.CBizSourcePosts sourcePosts = new AppLogic.DataAlc.CBizSourcePosts())
            {
                int pageIndex = 1;
                int pageRows = 10;
                int.TryParse(pIndex, out pageIndex);
                int.TryParse(pRows, out pageRows);
                string djackId = this.GetParamHtValue("djackId"); 
                DataSet ds = sourcePosts.GetVehicleForPageview(pageRows, pageIndex, djackId);
                if (ds == null || ds.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                this.ExecJScript(@"
                            var _html = $('#svc_list_temp').html();

                            laytpl(_html).render(" + retJson + @", function (render) {
                                $('#forumList').append(render);
                            });setPage('" + Convert.ToInt32(ds.Tables[0].Rows[0]["ROWSCOUNT"].ToString()) + "','" + pageIndex + "');");
            }
        }

    }
}